#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int N = 2e6 + 10;
int n, m;
int a[N], q[N];

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= n; i++) cin >> a[i];
	int h = 1, t = 0;
	cout << 0 << endl;
	for (int i = 1; i < n; i++) {
		while (h <= t && a[q[t]] >= a[i]) t--;
		q[++t] = i;
		if (q[h] < i - m + 1) h++;
		cout << a[q[h]] << endl;
	}
	return 0;
}